# -*- coding: utf-8 -*-
# @Time : 2022/3/17 15:53
# @FileName: resource_tool.py
# @Mail: lizhigen1996@aliyun.com

__author__ = 'Zhigen.li'

import os

def ReBuildResources():
    print('重构资源文件...')

    absPath = os.path.dirname(os.path.realpath(__file__))
    qrcPath = absPath + os.sep + 'resource.qrc'
    imgPath = absPath + os.sep + 'Img'
    stylesheetPath = absPath + os.sep + 'Stylesheet'
    recordPath = absPath + os.sep + 'Record'

    qrcStr = '<RCC>\n   <qresource prefix="/">\n'

    for file in os.listdir(imgPath):
        text = '        <file>Img/{}</file>\n'.format(file)
        qrcStr += text

    for file in os.listdir(stylesheetPath):
        text = '        <file>Stylesheet/{}</file>\n'.format(file)
        qrcStr += text

    for file in os.listdir(recordPath):
        text = '        <file>Record/{}</file>\n'.format(file)
        qrcStr += text

    qrcStr += '   </qresource>\n'
    qrcStr += '</RCC>\n'

    with open(qrcPath, 'w') as fp:
        fp.write(qrcStr)

    os.system('activate pytorch && cd {} && pyrcc5 -o resource_rc.py resource.qrc'.format(absPath))

    print('重构资源文件完成...')


if __name__ == '__main__':
    ReBuildResources()
